package com.victor.zjbj_android.yinhuan;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.victor.zjbj_android.R;
import com.victor.zjbj_android.yinhuan.fragment.AdressFragment;
import com.victor.zjbj_android.yinhuan.fragment.YihuanListFragment;

import java.util.ArrayList;
import java.util.List;

public class NewAdressActivity extends AppCompatActivity {
    private TabLayout mTablayout;
    private ViewPager mViewPager;
    private List<Fragment> fragments;

    private AdressFragment myFragment1;
    private AdressFragment myFragment2;
    private AdressFragment myFragment3;
    private AdressFragment myFragment4;

    private void initFragments() {
        myFragment1 = AdressFragment.newInstance(0);
        myFragment2 = AdressFragment.newInstance(1);
        myFragment3 = AdressFragment.newInstance(2);
        myFragment4 = AdressFragment.newInstance(3);
        fragments = new ArrayList<>();
        fragments.add(myFragment1);
        fragments.add(myFragment2);
        fragments.add(myFragment3);
        fragments.add(myFragment4);
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new_adress);
        initFragments();
        initViews();
    }

    private void initViews() {
        mViewPager=findViewById(R.id.viewPager);
        mTablayout=findViewById(R.id.tb_wenjian);
        MyYinHuanPagerAdapter myWenjianPagerAdapter=new MyYinHuanPagerAdapter(getSupportFragmentManager(),fragments,new String[]{"1号现场","2号现场","3号现场","4号现场"});
        mViewPager.setAdapter(myWenjianPagerAdapter);
        mTablayout.setupWithViewPager(mViewPager);
        mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                switch (position){
                    case 0:
//                        myFragment1.refresh(0);
                        break;
                    case 1:
//                        myFragment2.refresh(1);
                        break;
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }
}
